//
//  UILabel+Text.swift
//  AirlineReservation
//
//  Created by Kevin on 2019/12/26.
//  Copyright © 2019 Kevin. All rights reserved.
//

import UIKit

extension UILabel {
    
    convenience init(title:String = "",color:UIColor = UIColor.darkGray,size:CGFloat = 14,align:NSTextAlignment = .left) {
        self.init()
        // 文本
        text = title
        // 颜色
        textColor = color
        // 位置
        textAlignment = align
        // 用户交互
        isUserInteractionEnabled = true
        // 大小
        font = UIFont.systemFont(ofSize: size)
    }
    
    func getTextSize(str:String,w:Int,h:Int,fontSize:CGFloat) -> CGSize {
        return (str as NSString).boundingRect(with: CGSize(width: w, height: h), options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font : UIFont.systemFont(ofSize: fontSize)], context: nil).size
    }
}
